package com.zhao.modleclass.presenter;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.ScrollView;
import android.widget.Toast;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.zhao.modleclass.activity.SC_TeacherRActivity;
import com.zhao.modleclass.adapter.BiaoQianAdapter;
import com.zhao.modleclass.adapter.SC_MoDenTeacherAdapter;
import com.zhao.modleclass.adapter.SC_TeacherRActivityAdapter;
import com.zhao.modleclass.bean.SC_TeacherRActivityBean;
import com.zhao.modleclass.bean.SearchClassBiaoQianBean;
import com.zhao.modleclass.bean.SearchClassItemBean;
import com.zhao.modleclass.modle.ISearchModle;
import com.zhao.modleclass.modle.OnLoadSearchListener;
import com.zhao.modleclass.modle.SearchModle;
import com.zhao.modleclass.view.ISearchCLassView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 张昭 on 2016/11/29.
 */

public class SearchPresenter {
    private ISearchCLassView searchCLassView;
    private ISearchModle iSearchModle;
    private List<SearchClassBiaoQianBean.DataBean> mList = new ArrayList<>();
    private List<SearchClassItemBean.DataBean> mTList = new ArrayList<>();
    private BiaoQianAdapter adapter;
    private SC_MoDenTeacherAdapter mAdapter;
    private SC_TeacherRActivityAdapter rAdapter;

    public SearchPresenter(ISearchCLassView searchCLassView) {
        this.searchCLassView = searchCLassView;
        this.iSearchModle = new SearchModle();
    }

    public void login(final Context context,
                      final String type,
                      final Map<String, String> map,
                      final RecyclerView recyclerView,
                      final int tage
    ) {

        iSearchModle.login(type, map, new OnLoadSearchListener() {
            @Override
            public void onSucess(final SearchClassBiaoQianBean searchClassBiaoQianBean
            ) {
                mList = searchClassBiaoQianBean.getData();
                if (tage == 0) {
                    adapter = new BiaoQianAdapter(context, mList, recyclerView);
                    searchCLassView.toSetAdapter(adapter);
                    searchCLassView.getTeacher(searchClassBiaoQianBean);
                    searchCLassView.getTatle(searchClassBiaoQianBean.getTagList());
                } else {
                    adapter.reloadRecyclerView(mList, false);
                }

            }

            @Override
            public void onSucessTeacher(SearchClassItemBean searchClassItemBean) {

            }

            @Override
            public void onSucessMoreTag(SC_TeacherRActivityBean sc_teacherRActivityBean) {

            }

            @Override
            public void onFailed(Exception e) {
                searchCLassView.showError(e);
            }
        }, tage);
    }

    //全部跳转界面
    public void loginTeacher(final Context mContext,
                             final String type,
                             final Map<String, String> map,
                             final RecyclerView recyclerView,
                             final int taget
    ) {
        iSearchModle.loginTeacher(type, map, new OnLoadSearchListener() {
            @Override
            public void onSucess(SearchClassBiaoQianBean searchClassBiaoQianBean) {

            }

            @Override
            public void onSucessTeacher(final SearchClassItemBean searchClassItemBean) {
                mTList = searchClassItemBean.getData();
                if (taget == 0) {
                    mAdapter = new SC_MoDenTeacherAdapter(mContext, mTList, recyclerView);
                    searchCLassView.toSetItemAdapter(mAdapter);
                } else {
                    mAdapter.reloadRecyclerView(mTList, false);
                }
            }

            @Override
            public void onSucessMoreTag(SC_TeacherRActivityBean sc_teacherRActivityBean) {

            }

            @Override
            public void onFailed(Exception e) {
                Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }, taget);
    }

    //跳转更多标签
    public void loginTeacherMoreActyvity(final Context context,
                                         final String type,
                                         final Map<String, String> map,
                                         final RecyclerView rRecyclerView,
                                         final LinearLayoutManager manager,
                                         final int tager
    ) {
        iSearchModle.loginTeacherActivity(type, map, new OnLoadSearchListener() {
            @Override
            public void onSucess(SearchClassBiaoQianBean searchClassBiaoQianBean) {

            }

            @Override
            public void onSucessTeacher(SearchClassItemBean searchClassItemBean) {

            }

            @Override
            public void onSucessMoreTag(SC_TeacherRActivityBean sc_teacherRActivityBean) {
                if (tager == 0) {
                    rAdapter = new SC_TeacherRActivityAdapter(context, sc_teacherRActivityBean.getData(), rRecyclerView);
                    searchCLassView.toSetRAdapter(rAdapter);
                } else {
                    rAdapter.reloadRecyclerView(sc_teacherRActivityBean.getData(), false);
                }

            }

            @Override
            public void onFailed(Exception e) {

            }
        }, tager);
    }
}
